#ifndef _MCAS_H
#define _MCAS_H

#include <types.h>
#include <osal/osal.h>
#ifdef SUPPORT_HW_CONAX
	#include <api/libtsi/db_3l.h>
#endif

typedef enum {
	MCAS_DISP_NO_MSG = 0,	
	MCAS_DISP_CARD_IN,
	MCAS_DISP_CARD_OUT,
	MCAS_DISP_CARD_INITED,
	MCAS_DISP_CARD_NONE,
	MCAS_DISP_PIN_WRONG,
	MCAS_DISP_INPUT_PIN,
	MCAS_DISP_VIEW_PIN,
	MCAS_DISP_ORDER_PIN,
	MCAS_DISP_FINGER_IND,
	MCAS_DISP_FINGER_CLR,
	MCAS_DISP_HOST_MESSAGE,
	MCAS_DISP_HOST_MSGCLR,
	MCAS_DISP_MAT_CHANGE,
	MCAS_DISP_NO_ACCESS,
	MCAS_DISP_GEO_BLACKOUT,
	MCAS_DISP_NO_ACCESS_NET,
	MCAS_DISP_CARD_NON_EXIST,
	MCAS_DISP_CARD_INCOMPATIBLE,
	MCAS_DISP_INTERFACE_ERR,
	MCAS_DISP_CARD_ERROR,
	MCAS_DISP_NO_ACCESS_CLR,
	MCAS_DISP_NO_ACCESS_ERROR_CODE,
	MCAS_DISP_NO_ACCESS_NOT_SUBSCRIBED,
	MCAS_DISP_NO_SERVICE,
    MCAS_DISP_FINGER_PVR_IND,
	MCAS_DISP_CARD_INCOMPATIBLE_CONAX,
	MCAS_DISP_NO_CARD_CLR,
	MCAS_DISP_FINGER_ORIGINAL_IND,
} mcas_disp_type_t;


/************************
mcas working status
*************************/
#define MCAS_STATE_UNREGISTER	0x00
#define MCAS_STATE_IDLE		0x01
#define MCAS_STATE_ECM			0x02
#define MCAS_STATE_CAT			0x04
#define MCAS_STATE_EMM		0x08
#define MCAS_STATE_SERVICE_START	0x10

typedef enum {
	MCAS_NULL = 0,	
	MCAS_STOP,	
	MCAS_START_ECM,		/*change to a scrambled channel*/
	MCAS_GOT_ECM,		
	MCAS_START_CAT,		/*change to one TP and request CAT*/
	MCAS_GOT_CAT,		
	MCAS_START_EMM,		/*change to one TP and request EMM*/
	MCAS_GOT_EMM,		
	MCAS_CARD_IN,
	MCAS_CARD_OUT,
	MCAS_CARD_UPDATE,
	MCAS_INPUT_PIN,
	MCAS_VIEW_PIN,
	MCAS_ORDER_PIN,
	MCAS_FINGER_IND,
	MCAS_FINGER_CLR,
	MCAS_HOST_MESSAGE,
	MCAS_MAT_CHANGE,
	MCAS_NO_ACCESS,
	MCAS_GEO_BLACKOUT,
	MCAS_NO_ACCESS_NET,
	MCAS_CARD_NON_EXIST,
	MCAS_CARD_INCOMPATIBLE,
	MCAS_INTERFACE_ERR,
	MCAS_CARD_ERROR,
	MCAS_NO_ACCESS_CLR,
	MCAS_NO_ACCESS_ERROR_CODE
} mcas_msg_type_t;

typedef struct{
	mcas_msg_type_t type;
	UINT32 param;
} mcas_msg_t;

typedef void (*mcas_disp_func_t)(mcas_disp_type_t type, UINT32 param);

typedef struct
{
	OSAL_ID thread_id;
	OSAL_ID msgque_id;
	UINT16 state;
	mcas_disp_func_t disp_callback;
} mcas_t;


typedef struct{
	UINT16 pid;
	UINT16 ca_system_id;
	struct restrict filter_restrict;
    UINT8 dmx_id;       //indicate the filter belong to which dmx
    struct si_filter_t *sfilter;
} cas_filter_t;

typedef struct struct_CA_CHUNK_ID
{
	UINT32 ca_date_msgfp_id;
	UINT32 key_store_id;
	UINT32 reserved1;
	UINT32 reserved2;
	UINT32 reserved3;
}CA_CHUNK_ID_S,*P_CA_CHUNK_ID_S;


#define MAX_CA_AUDIO_CNT 16
typedef struct{
	UINT16 prog_number;

	UINT16 video_pid;

	UINT8  cur_audio;
	UINT16  audio_count;
	UINT16 audio_pid[MAX_CA_AUDIO_CNT];

	UINT16 subtitle_pid;
	UINT16 teletext_pid;
} ca_service_info;

/* NOR FLASH or NAND FLASH */
void api_mcas_init_sto_type(UINT32 type);
/* Export function for root */
INT32 api_mcas_register(mcas_disp_func_t mcas_disp_func);
INT32 api_mcas_unregister();
UINT8 ca_set_chunkid(P_CA_CHUNK_ID_S p_chunkid);
/* Export function for channal change */
#ifdef SUPPORT_2CA
#ifdef NEW_DEMO_FRAME
INT32 abv_mcas_start_service(UINT16 channel_index, UINT32 mon_id);
INT32 abv_mcas_stop_service(UINT32 mon_id);
#else
INT32 abv_mcas_start_service(UINT16 channel_index);
INT32 abv_mcas_stop_service();
#endif
INT32 abv_mcas_start_transponder();
INT32 abv_mcas_stop_transponder();
#endif
#ifdef NEW_DEMO_FRAME
INT32 api_mcas_start_service(UINT32 channel_index, UINT32 mon_id);
INT32 api_mcas_start_service_multi_des(UINT32 channel_index, UINT32 mon_id, UINT8 dmx);
INT32 api_mcas_stop_service(UINT32 mon_id);
INT32 api_mcas_stop_service_multi_des(UINT32 prog_id,UINT32 mon_id);
#else
INT32 api_mcas_start_service(UINT32 channel_index);
INT32 api_mcas_stop_service();
#endif
INT32 api_mcas_start_transponder();
INT32 api_mcas_start_transponder_multi_des(UINT8 dmx_id);
INT32 api_mcas_stop_transponder();
INT32 api_mcas_stop_transponder_multi_des(UINT8 dmx_id);
#ifdef SUPPORT_HW_CONAX
INT32 mcas_set_prog_info(P_NODE *p_node);
#endif

void api_mcas_get_emm_pid(UINT16 * pidlist,UINT8 * len,UINT8 dmx);
INT32 api_mcas_request_tdt();
void api_mcas_get_playback_utc(UINT8 * time);
void api_mcas_stop_playback_tdt(void);
UINT8 api_mcas_playback_utc_init(void);
void api_mcas_set_playback_utc_init(UINT8 flag);

INT8 api_mcas_get_prog_record_flag(UINT32 prog_id);
void api_mcas_set_prog_record_flag(UINT32 prog_id, UINT8 flag);
/*search the session according to prog_id,if success return session_id,else return -1*/
INT8 api_mcas_get_session_by_prog(UINT32 prog_id);

#endif


